package cn.tedu.ivoscm.geofence.controller;

import cn.tedu.ivoscm.base.response.JsonResult;
import cn.tedu.ivoscm.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivoscm.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivoscm.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivoscm.geofence.service.GeofenceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/geofence")
@Api(tags = "03.电子围栏管理")
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;

    @GetMapping("select")
    @ApiOperation(value = "查询电子围栏信息")
    @ApiOperationSupport(order = 10)
    public JsonResult select(GeofenceQuery gq) {
        log.debug("开始处理查询电子围栏信息请求，参数：{}", gq);
        List<GeofenceVO> list = geofenceService.select(gq);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    @ApiOperation(value = "修改电子围栏状态")
    @ApiOperationSupport(order = 50)
    public JsonResult save(@RequestBody GeofenceSaveParam gsp) {
        log.debug("保存围栏状态参数：{}", gsp);
        geofenceService.save(gsp);
        return JsonResult.ok();
    }

    @PostMapping("update/status/{id}/{status}")
    @ApiOperation(value = "修改电子围栏状态")
    @ApiOperationSupport(order = 50)
    public JsonResult updatePassword(@PathVariable Long id, @PathVariable String status) {
        log.debug("修改围栏状态参数：id: {}, status: {}", id, status);
        geofenceService.updateStatus(id, status);
        return JsonResult.ok();
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "删除电子围栏信息")
    @ApiOperationSupport(order = 60)
    public JsonResult delete(@PathVariable Long id) {
        log.debug("开始处理删除电子围栏信息请求，参数：{}", id);
        geofenceService.deleteById(id);
        return JsonResult.ok();
    }

}